package com.design.controller.web;

import com.design.dao.entity.Template;
import com.design.model.BaseResult;
import com.design.model.PageResult;
import com.design.service.TemplateService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@Api(tags = "【WEB端-车板管理】")
@RequestMapping("/template")
@CrossOrigin(origins = "*")
public class TemplateController {

    @Autowired
    private TemplateService templateService;

    @ApiOperation(value = "车板管理-查询车板列表")
    @GetMapping("/queryByPage")
    public PageResult<List<Template>> queryByPage(String templateNum, Integer pageNum, Integer pageSize) {
        return templateService.queryByPage(templateNum, pageNum, pageSize);
    }


    @ApiOperation(value = "车板管理-新增/编辑车板")
    @PostMapping("/edit")
    public BaseResult<Void> edit(@RequestBody Template template) {
        templateService.edit(template);
        return new BaseResult<>();
    }

    @ApiOperation(value = "车板管理-删除车板")
    @PostMapping("/remove")
    public BaseResult<Void> remove(@RequestBody Map<String,Integer> map) {
        templateService.remove(map.get("id"));
        return new BaseResult<>();
    }
}
